package com.md.value.enums;

import com.md.base.EnumBase;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 刘骄阳
 * 2023-08-08 16:54
 */
@Getter
@AllArgsConstructor
public enum AliYunSmsEnum implements EnumBase {
  /**
   * 成功
   */
  OK(0, "成功", "OK"),

  /**
   * RAM权限DENY
   */
  RAM_PERMISSION_DENY(1, "RAM权限DENY", "isp.RAM_PERMISSION_DENY"),

  /**
   * 业务停机
   */
  OUT_OF_SERVICE(2, "业务停机", "isv.OUT_OF_SERVICE"),

  /**
   * 账户不存在
   */
  ACCOUNT_NOT_EXISTS(3, "账户不存在", "isp.ACCOUNT_NOT_EXISTS"),

  /**
   * 账户异常
   */
  ACCOUNT_ABNORMAL(4, "账户异常", "isv.ACCOUNT_ABNORMAL"),

  /**
   * 参数异常
   */
  INVALID_PARAMETERS(5, "参数异常", "isp.INVALID_PARAMETERS"),

  /**
   * 非法手机号
   */
  MOBILE_NUMBER_ILLEGAL(6, "非法手机号", "isv.MOBILE_NUMBER_ILLEGAL"),

  /**
   * 手机号码数量超过限制
   */
  MOBILE_COUNT_OVER_LIMIT(7, "手机号码数量超过限制", "isp.MOBILE_COUNT_OVER_LIMIT"),

  /**
   * 业务限流
   */
  BUSINESS_LIMIT_CONTROL(8, "业务限流", "isv.BUSINESS_LIMIT_CONTROL"),

  /**
   * 参数超出长度限制
   */
  PARAM_LENGTH_LIMIT(9, "参数超出长度限制", "isp.PARAM_LENGTH_LIMIT"),

  /**
   * 不支持URL
   */
  PARAM_NOT_SUPPORT_URL(10, "不支持URL", "isv.PARAM_NOT_SUPPORT_URL"),

  /**
   * 账户余额不足
   */
  AMOUNT_NOT_ENOUGH(11, "账户余额不足", "isv.AMOUNT_NOT_ENOUGH");

  static final Map<Integer, AliYunSmsEnum> ENUM_MAP = Arrays.stream(AliYunSmsEnum.values())
    .collect(Collectors.toMap(AliYunSmsEnum::getCode, e -> e));

  static final Map<String, AliYunSmsEnum> ENUM_MAP_STRING = Arrays.stream(AliYunSmsEnum.values())
    .collect(Collectors.toMap(AliYunSmsEnum::getMessage, e -> e));
  private final Integer code;
  private final String info;
  private final String message;

  public static AliYunSmsEnum of(final Integer code) {
    return ENUM_MAP.get(code);
  }

  /**
   * 根据值获取对应的枚举
   *
   * @param message code 值
   * @return 枚举对应的值
   */
  public static AliYunSmsEnum of(final String message) {
    return ENUM_MAP_STRING.get(message);
  }


}
